package com.wyyc.common.register.controller;

import com.alibaba.fastjson.JSON;
import com.wyyc.common.register.service.RegisterService;
import com.wyyc.entity.ResJson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by Hwei~ on 2017/6/6.
 */
@Controller
@RequestMapping("request/user/register")
public class RegisterController {

    @Resource
    private RegisterService registerService;

    /**
     * 发送验证码
     * @param phone 手机号
     * @return 状态
     */
    @RequestMapping(value = "sendCode",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String sendCode(String phone){
        if (phone!=null&&!phone.equals("")){
            ResJson resJson = registerService.sendCode(phone);
            return JSON.toJSONString(resJson);
        }
        return "";
    }

    @RequestMapping(value = "addUser",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String addUser(String phone,String code){
        if (phone!=null&&!phone.equals("")){
            if (code!=null&&!code.equals("")){
                ResJson resJson = registerService.addUser(phone,code);
                return JSON.toJSONString(resJson);
            }
        }
        return "";
    }
}
